package com.polaris.live.adapter.level

import android.view.View
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.polaris.live.R
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.AdapterMeRichCharmBannerBinding
import com.polaris.live.resp.back_resp.UserRichCharmConfigVo
import com.polaris.live.utils.image.ImageUtils
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder

/**
 * 壕等级魅等级页顶部轮播图适配器
 *
 * @author Created by 半仙 on 2024/9/18/018 14:56
 */
class MeRichCharmBannerAdapter : BaseBannerAdapter<UserRichCharmConfigVo>() {

    override fun createViewHolder(
        parent: ViewGroup,
        itemView: View,
        viewType: Int,
    ): BaseViewHolder<UserRichCharmConfigVo> {
        return MeRichCharmViewHolder(AdapterMeRichCharmBannerBinding.bind(itemView))
    }


    override fun bindData(
        holder: BaseViewHolder<UserRichCharmConfigVo>?,
        data: UserRichCharmConfigVo?,
        position: Int,
        pageSize: Int,
    ) {
        if (holder is MeRichCharmViewHolder) {
            holder.binding.apply {
                Glide.with(root.context).load(ImageUtils.imgPath(data?.icon)).into(ivLevel)
                tvLevel.text = "Lv${data?.minLevel} — Lv${data?.maxLevel}"
            }
            holder.binding.root.setOnSingleClickListener {
                data?.let { it1 -> onClickItemCallback?.invoke(position, it1) }
            }
        }
    }

    override fun getLayoutId(viewType: Int): Int {
        return R.layout.adapter_me_rich_charm_banner
    }

    private var onClickItemCallback: ((position: Int, data: UserRichCharmConfigVo) -> Unit)? = null

    fun setOnClickItemCallback(l: ((position: Int, data: UserRichCharmConfigVo) -> Unit)) {
        onClickItemCallback = l
    }

    class MeRichCharmViewHolder(val binding: AdapterMeRichCharmBannerBinding) :
        BaseViewHolder<UserRichCharmConfigVo>(binding.root)
}